package com.kundi.dooradmin.controller;

import com.kundi.dooradmin.entity.CooperationUnit;
import com.kundi.dooradmin.service.CooperationUnitService;
import com.kundi.dooradmin.util.MapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Author 赵恒
 * Date 2020/6/19
 */
@Controller
@RequestMapping("/cooperationUnit")
public class CooperationUnitController {
    @Resource
    CooperationUnitService cooperationUnitService;
    @RequestMapping("/getAll")
    @ResponseBody
    public List<CooperationUnit> getAll() {
        return cooperationUnitService.getAll();
    }

    @RequestMapping("/insert")
    @ResponseBody
    public Map<String, String> insert(CooperationUnit cooperationUnit) {
        int i = cooperationUnitService.insert(cooperationUnit);
        if(i > 0) {
           return MapUtil.responseMap("添加成功", "true");
        } else {
           return MapUtil.responseMap("添加失败", "false");
        }
    }
    @RequestMapping("/update")
    @ResponseBody
    public Map<String, String> update(CooperationUnit cooperationUnit) {
        int i = cooperationUnitService.update(cooperationUnit);
        if(i > 0) {
            return MapUtil.responseMap("修改成功", "true");
        } else {
            return MapUtil.responseMap("修改失败", "false");
        }
    }
    @RequestMapping("/delete")
    @ResponseBody
    public Map<String, String> delete(Integer id) {
        int i = cooperationUnitService.delete(id);
        if(i > 0) {
            return MapUtil.responseMap("删除成功", "true");
        } else {
            return MapUtil.responseMap("删除失败", "false");
        }
    }

    @RequestMapping("/getUnitById")
    @ResponseBody
    public CooperationUnit getUnitById(Integer id) {
        return cooperationUnitService.getUnitById(id);
    }
}
